var _n26;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$uiService = require("uiService");
var s = cc__importDefault($1$uiService);
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var $gameMode_Json = require("gameMode_Json");
var $1$zqcc_pageBase = require("zqcc_pageBase");
var u = cc__importDefault($1$zqcc_pageBase);
var $1$PaintCtrl = require("PaintCtrl");
var p = cc__importDefault($1$PaintCtrl);
var $1$PaintBoard = require("zqcc_PaintBoard");
var d = cc__importDefault($1$PaintBoard);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_OverPage = function (t) {
  function _ctor() {
    var e = null !== t && t.apply(this, arguments) || this;
    e.pageName = "失败页";
    e.paintCtrl = null;
    e.restart = null;
    e.nextBtn = null;
    e.lossNode = null;
    e.passTitle = null;
    e.lossTitle = null;
    e.jinduNode = null;
    e.shareBtn1 = null;
    e.shareBtn2 = null;
    return e;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.setCloseDoFun = function (t) {
    this.colseDoFun = t;
  };
  _ctor.prototype.start = function () {
    // 打开当前界面
    this.open();

    // 检查游戏屏幕录制状态
    const isRecording = $zqcc_OverallSystem.sers().platformSrv.platformApi.recordedGameScreenStop();

    // 根据录制状态设置分享按钮的可见性
    this.shareBtn1.active = !isRecording; // 当未录制时显示按钮1
    this.shareBtn2.active = isRecording;   // 当录制时显示按钮2
  };
  _ctor.prototype.initData = function (t) {
    let iconNode = null;

    // 处理游戏未通过的情况
    if (!t.pass) {
      cc.log("zhanshi");

      iconNode = this.lossTitle.getChildByName("icon");
      this.passTitle.active = false;
      this.lossTitle.active = true;
      this.restart.active = true;
      this.nextBtn.active = false;

      const loseSpine = this.lossTitle.getChildByName("loseSpine");

      // 设置失误动画
      loseSpine.getChildByName("huangguan").getComponent(sp.Skeleton).setCompleteListener((event) => {
        // Handle complete event for huangguan animation if necessary
        event.animation && event.animation.name;
      });

      const starSkeleton = loseSpine.getChildByName("xingxing").getComponent(sp.Skeleton);
      starSkeleton.setAnimation(0, "tanchu", false);
      starSkeleton.setCompleteListener((event) => {
        if (event.animation && event.animation.name === "tanchu") {
          starSkeleton.setAnimation(0, "zhuan", true);
        }
      });
    }

    // 处理游戏通过的情况
    if (t.pass) {
      this.lossNode.active = false;
      this.passTitle.active = true;
      this.lossTitle.active = false;
      this.restart.active = false;
      this.nextBtn.active = true;

      const winSpine = this.passTitle.getChildByName("winSpine").getChildByName("xingxing").getComponent(sp.Skeleton);
      winSpine.setAnimation(0, "tanchu", false);
      winSpine.setCompleteListener((event) => {
        if (event.animation && event.animation.name === "tanchu") {
          winSpine.setAnimation(0, "zhuan", true);
        }
      });

      iconNode = this.passTitle.getChildByName("icon");
    }

    // 更新捕获节点
    this.captureNode = iconNode.getChildByName("captureNode");

    // 更新进度节点
    if (t.data.gameProgress >= 0) {
      this.jinduNode.active = true;

      const progressBarNode = this.jinduNode.children[1];
      const progressLabel = progressBarNode.children[1].getComponent(cc.Label);
      const progress = 382 * t.data.gameProgress;

      cc.tween(progressBarNode).by(0.5, { x: progress }).start();
      cc.tween(this.jinduNode.getComponent(cc.ProgressBar)).to(0.5, { progress: t.data.gameProgress }).start();

      const totalSteps = Math.round(100 * t.data.gameProgress);

      const updateLabel = (step) => {
        this.scheduleOnce(() => {
          progressLabel.string = `${step}%`; // 更新显示进度
        }, 0.5 / totalSteps * step);
      };

      for (let step = 1; step <= totalSteps; step++) {
        updateLabel(step);
      }
    }

    // 更新画板节点
    this.paintNode = t.data.paintNode;
    this.paintNode.parent = iconNode;
    this.paintNode.scale = 0.85;
    this.paintNode.setPosition(0, 20);
    this.paintNode.removeComponent(cc.Widget);

    const paintComponent = this.paintNode.getComponent(d.default);
    paintComponent.maskNode = null;
    this.paintCtrl.setPaintBoard(paintComponent);


  };
  _ctor.prototype.share = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    this.shareImage(this.captureNode);
  };
  _ctor.prototype.share2 = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    $zqcc_OverallSystem.sers().platformSrv.platformApi.shareRecordedGameScreen();
  };
  _ctor.prototype.newGame = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    $zqcc_OverallSystem.mgrs().gameMgr.enterMode($gameMode_Json.GAME_MODE.Feibiao);
  };
  _ctor.prototype.restartGame = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    $zqcc_OverallSystem.sers().platformSrv.platformApi.hideBanner();
    $zqcc_OverallSystem.mgrs().gameMgr.enterMode($gameMode_Json.GAME_MODE.Feibiao);
  };
  _ctor.prototype.open = function () {
    s.default.openPageBasicAni(this.showNode, true).then(function () { }).catch(function () { });
  };
  _ctor.prototype.close = function () {
    // 隐藏平台广告横幅
    $zqcc_OverallSystem.sers().platformSrv.platformApi.hideBanner();

    // 关闭动画并处理后续逻辑
    this.closeAni()
      .then(() => {
        $zqcc_OverallSystem.sers().uiSrv.deletePageRecord(this.id); // 删除页面记录
        this.node.destroy(); // 销毁当前节点
      })
      .catch(error => {
        console.error("Error during closing animation:", error); // 处理可能的错误
      });
  };
  _ctor.prototype.onlyClose = function () {
    const context = this; // 使用更具描述性的变量名

    // 执行关闭动画并处理后续逻辑
    this.closeAni()
      .then(() => {
        $zqcc_OverallSystem.sers().uiSrv.deletePageRecord(context.id); // 删除页面记录
        context.node.destroy(); // 销毁当前节点
      })
      .catch(error => {
        console.error("Error during closing animation:", error); // 处理可能的错误
      });
  };
  _ctor.prototype.OnBtnClose = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    $zqcc_OverallSystem.mgrs().gameMgr.backHomePage();
    this.close();
    cc.log("OnBtnClose");
  };
  _ctor.prototype.backIndex = function () {
    $zqcc_OverallSystem.mgrs().soundMgr.playBtnSound();
    this.OnBtnClose();
  };
  _ctor.prototype.closeAni = function (t) {
    undefined === t && (t = false);
    return s.default.closePageBasicAni(this.showNode, t);
  };
  _ctor.prototype.update = function () { };
  _ctor.prototype.shareImage = function (t) {
    // 获取元素的世界边界框
    const boundingBox = t.getBoundingBoxToWorld();
    const canvas = cc.game.canvas;
    const scaleFactor = canvas.height / cc.view.getVisibleSize().height; // 计算缩放因子

    // 创建分享信息对象
    const shareInfo = {
      x: boundingBox.x * scaleFactor, // 计算分享区域的左上角 x 坐标
      y: canvas.height - (boundingBox.y + boundingBox.height) * scaleFactor, // 计算分享区域的左上角 y 坐标
      width: boundingBox.width * scaleFactor, // 计算分享区域的宽度
      height: boundingBox.height * scaleFactor, // 计算分享区域的高度
      destWidth: 500, // 目标宽度
      destHeight: 400 // 目标高度
    };

    // 调用平台 API 分享应用信息
    $zqcc_OverallSystem.sers().platformSrv.platformApi.shareAppMessage("", "", shareInfo);
  };
  cc__decorate([ccp_property(p.default)], _ctor.prototype, "paintCtrl", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "restart", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "nextBtn", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "lossNode", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "passTitle", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "lossTitle", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "jinduNode", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "shareBtn1", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "shareBtn2", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(u.default);
exports.default = def_OverPage;